#import "NSArray+Log.h"
#import "NSString+Format.h"
@implementation NSNumber (Test)

- (void)drawWithRect:(CGRect)rect options:(NSStringDrawingOptions)options attributes:(nullable NSDictionary<NSString *, id> *)attributes context:(nullable NSStringDrawingContext *)context {
    return [Format(@"%@",self) drawWithRect:rect options:options attributes:attributes context:context];
}

- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(nullable NSDictionary<NSString *, id> *)attributes context:(nullable NSStringDrawingContext *)context {
    print(@"123");
    return [Format(@"%@",self) boundingRectWithSize:size options:options attributes:attributes context:context];
}

- (NSRange)rangeOfCharacterFromSet:(NSCharacterSet *)searchSet {
    return [Format(@"%@",self) rangeOfCharacterFromSet:searchSet];
}
- (NSRange)rangeOfCharacterFromSet:(NSCharacterSet *)searchSet options:(NSStringCompareOptions)mask {
    return [Format(@"%@",self) rangeOfCharacterFromSet:searchSet options:mask];
}
- (NSRange)rangeOfCharacterFromSet:(NSCharacterSet *)searchSet options:(NSStringCompareOptions)mask range:(NSRange)rangeOfReceiverToSearch {
    return [Format(@"%@",self) rangeOfCharacterFromSet:searchSet options:mask range:rangeOfReceiverToSearch];
}

@end

@implementation NSArray (Log)

- (NSInteger)length {
    return self.count;
}

- (NSString *)descriptionIndent:(NSInteger)level {
    
    NSMutableString *indent = [NSMutableString string];
    for (NSInteger i = 0; i < level; i++) {
        [indent appendString:@"\t"];
    }
    
    NSMutableString *result = [NSMutableString stringWithFormat:@"\n%@[\n", indent];
    
    [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        id item = [obj respondsToSelector:@selector(descriptionIndent:)] ? [obj descriptionIndent:level + 1] : obj;
        if ([obj isKindOfClass:[NSString class]]) {
            [result appendFormat:@"\t%@\"%@\",\n", indent, item];
        } else {
            [result appendFormat:@"\t%@%@,\n", indent, item];
        }
        
    }];
    
    [result appendString:[NSMutableString stringWithFormat:@"%@]", indent]];
    return result;
}

- (NSString *)description {
    return [self descriptionIndent:0];
}

- (NSString *)descriptionWithLocale:(id)locale
{
    return [self descriptionIndent:0];
}

@end

@implementation NSDictionary (Log)

- (NSInteger)length {
    return self.count;
}

- (NSString *)description {
    return [self descriptionIndent:0];
}

- (NSString *)descriptionIndent:(NSInteger)level {
    
    NSMutableString *indent = [NSMutableString string];
    for (NSInteger i = 0; i < level; i++) {
        [indent appendString:@"\t"];
    }
    
    NSMutableString *result = [NSMutableString stringWithFormat:@"\n%@{\n", indent];
    
    [self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
        id item = [obj respondsToSelector:@selector(descriptionIndent:)] ? [obj descriptionIndent:level + 1] : obj;
        if ([obj isKindOfClass:[NSString class]]) {
            [result appendFormat:@"\t%@\"%@\":\"%@\",\n", indent, key, item];
        } else {
            [result appendFormat:@"\t%@\"%@\":%@,\n", indent, key, item];
        }
        
    }];
    
    [result appendString:[NSMutableString stringWithFormat:@"%@}", indent]];
    return result;
}

- (NSString *)descriptionWithLocale:(id)locale
{
    return [self descriptionIndent:0];
}

@end
